using System;
using System.Collections.Generic;
using System.Linq;
using BepInEx;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Drawing;
using HarmonyLib;
using Hearthstone;
using Hearthstone.Progression;
using PegasusLettuce;
using PegasusShared;
using PegasusUtil;
using UnityEngine;
using System.Threading;

namespace Mercenary
{
    internal class PluginInfo
    {
        public const string PLUGIN_GUID = "UniverseString";
        public const string PLUGIN_NAME = "免费佣兵插件";
        public const string PLUGIN_VERSION = "7.2.0";
        public const string PLUGIN_DATE = "[2022-11-05]";
    }

    public class UtilsGui : BaseUnityPlugin
    {
        public static string title = "V" + PluginInfo.PLUGIN_VERSION +"--"+ PluginInfo.PLUGIN_DATE;
        public static UiItem modeConf=UiItemConst.模式_挂机收菜;
        public static UiItem strategyConf=UiItemConst.策略_PVE通用;
        public static bool autoConcede = false;
        public static bool autoCraftConf=true;
        public static bool autoUpdateSkillConf=false;
        public static int pvpDelayTime=10;
        public static int pveInterval = 22*60;
        public static bool readyToHang = false;
        public static bool needToHang = true;
        public static string hash="";
        public static string path="";
        public static int pvpRating = 0;
        public static string errCode = "";
        public static bool bEnable = false;

        public static void BuildGui(ref bool bRunning)
        {
            GUIStyle textStyle = new GUIStyle();
            textStyle.normal.textColor = Color.white;
            textStyle.fontSize = 15;

            if (!bEnable) return;

            //标题
            GUILayout.BeginHorizontal(GUILayout.Width(220f));
            GUILayout.Label(new GUIContent("插件版本："),textStyle,GUILayout.Width(70f));
            GUILayout.Label(new GUIContent(title),textStyle);
            GUILayout.EndHorizontal();

            //运行状态
            GUILayout.BeginHorizontal(GUILayout.Width(220f));
            string status = bRunning ? "运行中" : "已停止";
            textStyle.normal.textColor = Color.green;
            if (errCode.Length > 0)
            {
                textStyle.normal.textColor = Color.red;
                status += ("--" + errCode);
            }

            GUILayout.Label(new GUIContent("运行状态："),textStyle,GUILayout.Width(70f));
            GUILayout.Label(new GUIContent(status),textStyle);
            GUILayout.EndHorizontal();

            //当前模式
            GUILayout.BeginHorizontal(GUILayout.Width(220f));
            textStyle.normal.textColor = Color.white;
            GUILayout.Label(new GUIContent("当前模式："),textStyle,GUILayout.Width(70f));
            GUILayout.Label(new GUIContent(modeConf.m_name),textStyle);
            GUILayout.EndHorizontal();

            //收菜间隔
            if (modeConf.m_id == UiItemConst.模式_挂机收菜.m_id)
            {
                GUILayout.BeginHorizontal(GUILayout.Width(220f));
                GUILayout.Label(new GUIContent("收菜间隔："), textStyle, GUILayout.Width(70f));
                GUILayout.Label(new GUIContent(
                    (pveInterval / 60).ToString() + "分" +
                    (pveInterval % 60).ToString() + "秒"),textStyle);
                GUILayout.EndHorizontal();
            }

            //当前策略
            GUILayout.BeginHorizontal(GUILayout.Width(220f));
            GUILayout.Label(new GUIContent("当前策略："),textStyle,GUILayout.Width(70f));
            GUILayout.Label(new GUIContent(strategyConf.m_name),textStyle);
            GUILayout.EndHorizontal();

            //卡组
            GUILayout.BeginHorizontal(GUILayout.Width(220f));
            GUILayout.Label(new GUIContent("当前卡组："), textStyle, GUILayout.Width(70f));
            GUILayout.Label(new GUIContent(UtilsTeam.m_teamName), textStyle);
            GUILayout.EndHorizontal();

            //地图
            if (modeConf.m_id != UiItemConst.模式_真人PVP.m_id)
            {
                GUILayout.BeginHorizontal(GUILayout.Width(220f));
                GUILayout.Label(new GUIContent("当前地图："), textStyle, GUILayout.Width(70f));
                GUILayout.Label(new GUIContent(UtilsMap.m_currMap.m_name), textStyle);
                GUILayout.EndHorizontal();
            }
            else
            {
                GUILayout.BeginHorizontal(GUILayout.Width(220f));
                GUILayout.Label(new GUIContent("当前分数："), textStyle, GUILayout.Width(70f));
                GUILayout.Label(new GUIContent(pvpRating.ToString()), textStyle);
                GUILayout.EndHorizontal();
            }

            //自动功能
            GUILayout.BeginHorizontal(GUILayout.Width(220f));
            GUILayout.Label(new GUIContent("自动功能："), textStyle, GUILayout.Width(70f));
            GUILayout.Label(new GUIContent(
                (autoConcede ? "[PVP投降]" : "") + 
                (autoCraftConf ? "[制作佣兵]" : "") + 
                (autoUpdateSkillConf ? "[升级技能]" : "")), textStyle);
            GUILayout.EndHorizontal();

            //运行开关
            string click=bRunning?"停止运行":"开始运行";
            if(GUILayout.Button(click))
            {
                bRunning=!bRunning;
                if (!bRunning) errCode = "用户主动停止";
                else errCode = "";
            }
        }
    }
}
